const { regClass } = Laya;
import { ScreenShotBase } from "./ScreenShot.generated";

@regClass()
export class ScreenShot extends ScreenShotBase {
    onAwake(): void {
        console.log(this.Img1);
        console.log(this.Img2);
        console.log(this.ImgSp);

        this.Img1.on(Laya.Event.LOADED, this, () => {
            console.log("Img1图片加载完成");
            Laya.timer.frameOnce(1, this, () => {
                console.log("setTimeout Img1图片加载完成");
                // setTimeout(() => {
                let rt2d = this.Img1.drawToRenderTexture2D(this.Img1.width, this.Img1.height, 0, 0)
                let tex = new Laya.Texture(rt2d, Laya.Texture.INV_UV);
                this.Img2.source = tex;
                // }, 1);
            })
        })

        this.BtnClick.on(Laya.Event.CLICK,this,()=>{
            // drawToRenderTexture2D 把当前容器内的画面绘制到新的的RenderTexture上
            // 前两个参数制定 从上一个容器中复制的区域
            // 后两个参数制定 相对左上角的偏移

            let rt2d = this.Img1.drawToRenderTexture2D(this.Img1.width/2,this.Img1.height/2,10,10)
            let tex = new Laya.Texture(rt2d, Laya.Texture.INV_UV);
            this.ImgSp.graphics.drawTexture(tex, 0, 0, this.ImgSp.width/2, this.ImgSp.height/2);
            this.Img2.source = tex;
        })
    }
}